import pandas as pd
# 1. 模拟脏数据
data_clean = {
    "姓名": ["张三","李四","王五","张三",None,"赵六"],
    "年龄": [18,None,18,18,20,19],
    "语文成绩": [85,92,None,85,90,88],
    "数学成绩": [90,85,82,90,95,88]
}
df_clean = pd.DataFrame(data_clean)
print("=== 原始脏数据 ===")
print(df_clean)
# 2. 缺失值处理
print("\n=== 缺失值统计 ===")
print(df_clean.isnull().sum())  # 每列缺失数
df_fill = df_clean.copy()
df_fill["年龄"] = df_fill["年龄"].fillna(df_fill["年龄"].mean())  # 均值填充
df_fill["语文成绩"] = df_fill["语文成绩"].fillna(df_fill["语文成绩"].mean())
print("\n=== 填充后数据 ===")
print(df_fill)
# 3. 重复值处理
print("\n=== 去重后数据 ===")
df_no_dup = df_clean.drop_duplicates()
print(f"原始行数：{len(df_clean)} → 去重后：{len(df_no_dup)}")
print(df_no_dup)